package com.aat.dxfy.jiajiemi;

import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.Signature;
import java.security.cert.Certificate;

import org.apache.shiro.codec.Base64;

public class Test {

	public static void main(String[] args) {
		try {
			byte[] sign = new byte[1];
			
			FileInputStream in = new FileInputStream("F:\\ScriptX.pfx");

			KeyStore inputKeyStore = KeyStore.getInstance("pkcs12");

			inputKeyStore.load(in, "1".toCharArray());

			Certificate cert = inputKeyStore.getCertificate("scriptx");

			System.out.print(cert.getPublicKey());

			PrivateKey privk = (PrivateKey) inputKeyStore.getKey("scriptx", "1".toCharArray());
			
			Signature signature = Signature.getInstance("SHA256withRSA");

			// 初始化签名，由私钥构建
			signature.initSign(privk);

			signature.update(sign);
			

			byte[] signRes = signature.sign();
			
			System.out.println(Base64.decodeToString(signRes));
			
			in.close();

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
